<extend name="Common@Common:layui_cdn" />
<block name="title">
    <title>文章列表</title>
</block>
<block name="style">
    <style>
        .fl {
            float: left;
        }
        
        .fr {
            float: right;
        }
        
        .layui-table-cell {
            height: auto!important;
            white-space: normal;
        }
    </style>
</block>

<block name="main">
    <div class="layui-container" style="width:90%;margin-top:20px;">
        <div class="layui-clear">
            <a class="layui-btn fl" href="javascript:;" onclick="think_open('{:U('edit')}','添加',['40%','60%'],0)"> 添加</a>
            <a class="layui-btn layui-btn-danger think-btn" data-type="del" data-url="{:U('del')}">删除</a>
            <form method="GET" action="{:U('add')}" class="fr layui-form" style="width:400px;">
                <div class="layui-input-inline fl" style="width:100px;">
                    <php>$types = ['title'=>'文章名'];</php>
                    <select name="searchtype">
                        <foreach name="types" item="vo" key="k">
                            <option value="{$k}" <if condition="$_GET['searchtype'] eq $k">selected</if>>{$vo}</option>
                        </foreach>
                    </select>
                </div>
                <div class="layui-input-inline fr" style="width:300px;">
                    <button class="layui-btn fr" lay-submit>搜索</button>
                    <input type="text" class="layui-input fr" style="width:230px;" name="keywords" placeholder="请输入关键词" value="{$_GET['keywords']}">
                </div>
                <php> $condition = $_GET['searchtype'] && $_GET['keywords'] ? "/searchtype/".$_GET['searchtype']."/keywords/".$_GET['keywords'] : '';</php>
                <script>
                    var condition = '{$condition}';
                </script>
            </form>
        </div>
        <table id="list"></table>
        <!--  -->
        <script type="text/html" id="barDemo">
            <div class="layui-btn-group action-btn">
                <a class="layui-btn layui-btn-xs" onclick="think_open('/admin/content/edit/id/{{d.id}}','修改',['60%','90%'],0)">编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs mini_del" data-url="/admin/content/del/ids/{{d.id}}">删除</a>
            </div>
        </script>

        <script type="text/html" id="statusTpl">
            {{# if(d.status == 1){ }} <span class="layui-badge layui-bg-green">启用</span>{{# }else if(d.status == 0){ }}<span class="layui-badge">禁用</span>{{# } }}
        </script>

    </div>
</block>


<block name="script">
    <script>
        layui.use(['think'], function() {
            var think = layui.think,
                $ = layui.jquery;
            //第一个实例
            think.render({
                elem: '#list',
                // height: 500,
                url: '/api/content/getdata' + condition,
                page: true,
                cols: [
                    [ //表头
                        {
                            type: 'checkbox',
                            // fixed: 'left'
                        }, {
                            field: 'id',
                            title: 'ID',
                            sort: true,
                            width: 80,
                        }, {
                            field: 'title',
                            title: '文章名'
                        }, {
                            field: 'status',
                            title: '状态',
                            width: 100,
                            toolbar: '#statusTpl'
                        }, {
                            field: 'update_time',
                            title: '更新时间',
                            sort: true,
                            width: 200,
                            templet: function(d) {
                                return think_time(d.time, 'Y-m-d H:i:s'); //think_time()是think.js里面的方法
                            }
                        }, {
                            title: '操作',
                            width: 120,
                            align: 'center',
                            toolbar: '#barDemo'
                        }
                    ]
                ]
            }, '{$_GET["searchtype"]}', '{$_GET["keywords"]}');
        });
    </script>
</block>